package com.castle.fortress.admin.job.task;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.castle.fortress.admin.exchange.entity.ExchangeVoucherEntity;
import com.castle.fortress.admin.exchange.enums.VoucherStatusEnum;
import com.castle.fortress.admin.exchange.service.ExchangeVoucherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;


/**
 * 兑换券过期处理
 */
@Component("voucherExpiredTask")
public class VoucherExpiredTask implements ITask {

    @Autowired
    private ExchangeVoucherService exchangeVoucherService;

    @Override
    public void runTask(String params) {
        //查询过期时间小于等于当前时间的 然后修改状态为已过期
        final UpdateWrapper<ExchangeVoucherEntity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.le("expired_time", new Date());
        updateWrapper.eq("status", VoucherStatusEnum.UNUSED.getCode());
        updateWrapper.set("status", VoucherStatusEnum.EXPIRED.getCode());
        exchangeVoucherService.update(updateWrapper);
    }
}
